// pages/admin/income/incomeDetails/incomeDetails.js
const app = getApp();
import Api from '../../../../utils/http';
var util = require('../../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    detailsList: [],
    endMonth: util.formatMonth(new Date), //限制不可选取未来的月份
    currMonth: '查看本月',
    currDepartIndex: '',
    currDepart: '所有部门',
    // currKindsIndex: '',
    // currKinds: '所有分类',
    codes: null,
    departArr: [],

  },
  //选择月份
  bindMonthPicker: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      currMonth: e.detail.value
    })
    this.getRecycle(e.detail.value);
  },
  //选择部门
  bindDepartPicker: function (e) {
    var that = this;
   
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var _index = e.detail.value;
    var index = that.data.detailsList[_index].id;
    var departArr =that.data.departArr;
    console.log(departArr, index)
    console.log("155555")
    console.log(departArr[_index])
    that.setData({
      currDepartIndex: index,
      currDepart: departArr[_index]
    });
    console.log(that.data.currDepart)
    that.getRecycleadd(e);
  },
  // //选择分类
  // bindKindsPicker: function(e) {
  //   var that = this;
  //   console.log('picker发送选择改变，携带值为', e.detail.value)
  //   var _index = e.detail.value;
  //   this.setData({
  //     currKindsIndex: e.detail.value,
  //     currKinds: that.data.kindsArr[_index]
  //   })
  // },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getRecycleDetail();
    that.getDepartmentList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  //部门列表接口
  /**获取部门列表信息*/
  getDepartmentList: function () {
    var that = this;
    let uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.id,
      pageSize: 9,
    };
    console.log(param);
    Api.ajax('/app/Zmanage/departmentList', param).then(res => {
      console.log(res)
      if (res.code == 200) {
        let list = [];
        res.data.list.forEach(item => {
            let obj = {}
            obj.id = item.id

            list.push(obj)
          });
          let departArr = [];
        res.data.list.forEach(item => {
            let obj = {}
            //obj[''] = item.title
            departArr.push(item.title)
          }),
          that.setData({
            detailsList: list,
            departArr:departArr
          });
          console.log("11225555")
          console.log(that.data.detailsList)
      } else {
        wx.showToast({
          title: "暂时没有",
          icon: "none",
          duration: 2000,
        })
      }
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  //筛选收益明细
  getRecycleadd: function () {
    var that = this;
    // console.log(e, that.data);
    var uid = wx.getStorageSync('userid');
    var param = {
      type: 2,
      uid: uid.id,
      did: that.data.currDepartIndex
    }
    console.log(param)
    Api.ajax("/app/Zmanage/recycleDetail", param).then(res => {
      console.log(res)
      if (res.code == 200) {

        that.setData({
          dataList: res.data,
          codes: res.code
        })
      } else {
        that.setData({
          dataList: res.data,
          codes: res.code
        })
        wx.showToast({
          title: '暂无数据',
          icon: 'none',
          duration: 1000
        })
      }
    })
  },
  //筛选收益明细
  getRecycle: function (value) {
    var that = this;
    // console.log(e, that.data);
    var uid = wx.getStorageSync('userid');
    var param = {
      type: 2,
      uid: uid.id,
      time: value,
      did: that.data.currDepartIndex
    }
    console.log(param)
    Api.ajax("/app/Zmanage/recycleDetail", param).then(res => {
      console.log(res)
      if (res.code == 200) {

        that.setData({
          dataList: res.data,
          codes: res.code
        })
      } else {
        that.setData({
          dataList: res.data,
          codes: res.code
        })
        wx.showToast({
          title: '暂无数据',
          icon: 'none',
          duration: 1000
        })
      }
    })
  },
  //收益明细
  getRecycleDetail: function () {
    var that = this;
    var uid = wx.getStorageSync('userid');
    var param = {
      type: 2,
      uid: uid.id
      // did:
    }
    console.log(param)
    Api.ajax("/app/Zmanage/recycleDetail", param).then(res => {
      console.log(res)
      if (res.code == 200) {

        that.setData({
          dataList: res.data,
          codes: res.code
        })
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})